package com.wonyesoft.wuliu.acticity;

import httptools.HttpJsonTool;

import java.lang.reflect.Type;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javabeen.CargoownerInfo;
import javabeen.UserInfoBeen;

import org.json.JSONException;
import org.json.JSONObject;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RadioGroup;
import android.widget.TabHost;
import android.widget.TextView;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;
import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.wonyesoft.wuliu.AppContent;
import com.wonyesoft.wuliu.R;
import com.wonyesoft.wuliu.acticity.base.BaseActivity;
import com.wonyesoft.wuliu.acticity.utils.StringUtils;
import com.wonyesoft.wuliu.acticity.utils.ToastUtils;
import com.wonyesoft.wuliu.api.GagApi;
import com.wonyesoft.wuliu.model.User;
import com.wonyesoft.wuliu.vo.JsonRequest;
import com.wonyesoft.wuliu.vo.JsonResponse;
import com.wonyesoft.wuliu.vo.State;

public class UserInfoActivity extends BaseActivity implements OnClickListener {

	private TabHost mTabHost;

	private RadioGroup mRadioGroup;

	private TextView title, head_right, user_info_xingbie, photo,
			user_info_phone, user_info_dizi, user_info_sheng;

	private ImageView head_left;

	ImageView cargoimageView;
	
	private Button newinfo;

	private RequestParams params;

	public static Gson gson = new Gson();

	private HttpUtils http = new HttpUtils();

	private User user;

	private CargoownerInfo cargoownerInfo;

	private AppContent app;

	private UserInfoBeen userInfoBeen;

	@SuppressLint("NewApi")
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_userinfo);
		app = (AppContent) getApplication();
		app.addActivity(this);
		title = (TextView) findViewById(R.id.head_title);
		head_left = (ImageView) findViewById(R.id.head_left);
		user_info_xingbie = (TextView) findViewById(R.id.user_info_xingbie);
		photo = (TextView) findViewById(R.id.photo);
		user_info_phone = (TextView) findViewById(R.id.user_info_phone);
		user_info_dizi = (TextView) findViewById(R.id.user_info_dizi);
		user_info_sheng = (TextView) findViewById(R.id.user_info_sheng);
		newinfo = (Button) findViewById(R.id.user_info_newinfo);
		title.setText("用户资料");
		head_left.setVisibility(0);
		head_left.setOnClickListener(this);
		newinfo.setOnClickListener(this);
	//	upUserInfo();
		initViews();
	}

//	@Override
//	protected void onResume() {
//		// TODO Auto-generated method stub
//		super.onResume();
//		upUserInfo();
//
//	}

//	private void upUserInfo() {
//		HashMap<String, Object> data = new HashMap<String, Object>();
//		data.put("cargoownerid", app.userId);
//		HttpJsonTool httpJsonTool = new HttpJsonTool(this);
//		Type types = new TypeToken<List<CargoownerInfo>>() {
//		}.getType();
//		httpJsonTool.SetOnLister(new Handler() {
//			@Override
//			public void handleMessage(Message msg) {
//				// TODO Auto-generated method stub
//				super.handleMessage(msg);
//				if (msg.what == 1) {
//					cargoownerInfo = (CargoownerInfo) msg.obj;
//					
//				}
//			}
//		});
//		httpJsonTool.StartWork(data, GagApi.GET_CARGO_OWNER_INFO, types, null);
//	}

	protected void initViews() {

		if (app.userinfobeen != null) {
			userInfoBeen = app.userinfobeen;
		} else {
			openActivity(UserLoginActivity.class);
			this.finish();
		}
		if (userInfoBeen.getsBirthday() != null) {
			TextView user_info_Birthday = (TextView) findViewById(R.id.user_info_Birthday);
		//	Date a=new Date(userInfoBeen.getBirthday());
		//	SimpleDateFormat viewShowFormat = new SimpleDateFormat("yyyy年MM月dd日");
		//	viewShowFormat
			user_info_Birthday.setText(userInfoBeen.getsBirthday());
		}
		if (userInfoBeen.getCargoownername()!=null) {
			TextView user_info_Birthday = (TextView) findViewById(R.id.cargoowner_info_name);
			user_info_Birthday.setText(userInfoBeen.getCargoownername());
		}
		
		if (userInfoBeen.getEmail()!=null) {
			TextView cargoowner_info_email=(TextView) findViewById(R.id.cargoowner_info_email);
			cargoowner_info_email.setText(userInfoBeen.getEmail());
		}
		if (userInfoBeen.getJob()!=null) {
			TextView cargoowner_info_Job=(TextView) findViewById(R.id.cargoowner_info_Job);
			cargoowner_info_Job.setText(userInfoBeen.getJob());
		}
		if (userInfoBeen.getWechartid()!=null) {
			TextView cargoowner_info_Wechartid=(TextView) findViewById(R.id.cargoowner_info_Wechartid);
			cargoowner_info_Wechartid.setText(userInfoBeen.getWechartid());
		}
		if (userInfoBeen.getQq()!=null) {
			TextView cargoowner_info_Qq=(TextView) findViewById(R.id.cargoowner_info_Qq);
			cargoowner_info_Qq.setText(userInfoBeen.getQq());
		}
		if (userInfoBeen.getHeadportrait()!=null) {
			cargoimageView=(ImageView) findViewById(R.id.user_info_tou);
			BitmapUtils bitmapUtils=new BitmapUtils(this);
			bitmapUtils.display(cargoimageView, GagApi.IMAGE_PAHT_HOST+userInfoBeen.getHeadportrait());
		}
		if (userInfoBeen.getIdcardno()!=null) {
			 user_info_sheng=(TextView) findViewById(R.id.user_info_sheng);
			user_info_sheng.setText(userInfoBeen.getIdcardno());
			
		}
//		if (condition) {
//			
//		}
	}

	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.head_left:
			finish();
			break;
		case R.id.user_info_newinfo:
			Intent intent = new Intent(UserInfoActivity.this,
					UserNewInfoActivity.class);
			startActivityForResult(intent, 010);
		default:
			break;
		}
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		if (resultCode == 111) {
			//upUserInfo();
			Log.v("initViews", "获得了");
			initViews();
		}
	}

}
